/*
 * Copyright 2006-2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.martinimix.webflow.accessor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.webflow.context.servlet.ServletExternalContext;
import org.springframework.webflow.core.collection.MutableAttributeMap;
import org.springframework.webflow.execution.RequestContext;

/**
 * Provides an abstract HTTP servlet request object accessor.
 * 
 * @author Scott Rossillo
 *
 */
public abstract class AbstractHttpServletRequestObjectAccessor implements
		FlowObjectAccessor {

	/**
	 * Returns an attribute map containing the external context's request map.
	 * 
	 * @param context the current web flow <code>RequestContext</code>
	 * 
	 * @return an <code>MutableAttributeMap</code> containing the external
	 * context's request parameter map
	 */
	protected final MutableAttributeMap getRequestMap(RequestContext context) {
		return context.getExternalContext().getRequestMap();
	}

	/**
	 * Returns the <code>HttpServletRequest</code> for the given context.
	 * 
	 * @param context the current web flow <code>RequestContext</code>
	 * 
	 * @return the current <code>HttpServletRequest</code>
	 * 
	 * @throws ClassCastException if the external context is not an instance of
	 * <code>ServletExternalContext</code>
	 */
	protected final HttpServletRequest getHttpServletRequest(RequestContext context) {
		
		ServletExternalContext servletContext = (ServletExternalContext) context.getExternalContext();
		
		return servletContext.getRequest();
	}
	
	protected final HttpServletResponse getHttpServletResponse(RequestContext context) {
		
		ServletExternalContext servletContext = (ServletExternalContext) context.getExternalContext();
		
		return servletContext.getResponse();
	}
}
